//
//  GPCollectViewController.m
//  gupiao
//
//  Created by mac on 2019/8/15.
//  Copyright © 2019 mac. All rights reserved.
//

#import "GPCollectViewController.h"
#import "GPIndexListCell.h"
#import "DGPUtil.h"
#import "GPDetailModel.h"
#import "GPDetailViewController.h"
#import "HHYHeader.h"

@interface GPCollectViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong) NSArray *sourceArr;
@end

@implementation GPCollectViewController

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}

-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"我的收藏";
    //导航栏及状态栏
//    [self.navigationController.navigationBar setHidden:NO];
    //    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    UIBarButtonItem *backbutton = [[UIBarButtonItem alloc]init];
    backbutton.title = @"";
    self.navigationItem.backBarButtonItem =backbutton;
    self.navigationController.navigationBar.barTintColor = rgba(255, 64, 0, 1);
    //去掉透明后导航栏下边的黑边
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    UIColor * color =[UIColor whiteColor];
    NSDictionary * dict=[NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];
    self.navigationController.navigationBar.titleTextAttributes =dict;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self loadData];
}

-(void)loadData{
    NSArray *idArray = [USER_DEFAULTS objectForKey:[NSString stringWithFormat:@"%@_collect",[DGPUtil getCurrentUserID]]];
    NSString *plistPath = [[NSBundle mainBundle]pathForResource:@"InfoData" ofType:@"plist"];
    NSMutableDictionary *dataDic = [[NSMutableDictionary alloc]initWithContentsOfFile:plistPath];
    NSArray *array = [GPDetailModel mj_objectArrayWithKeyValuesArray:dataDic[@"data"]];;
    NSMutableArray *muArr = [NSMutableArray array];
    for (GPDetailModel *model in array) {
        if ([idArray containsObject:model.Id]) {
            [muArr addObject:model];
        }
    }
    self.sourceArr = muArr;
    [self.tableView reloadData];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.sourceArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    GPIndexListCell *cell = [GPIndexListCell cellWithTableView:tableView :indexPath];
    GPDetailModel *model = self.sourceArr[indexPath.row];
    cell.img.image = [UIImage imageNamed:model.img];
    cell.title.text = model.title;
    cell.date.text = [NSString stringWithFormat:@"%@ %@",model.date,@""];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    GPDetailViewController *dvc = [[GPDetailViewController alloc] init];
    dvc.navTitle = @"详情";
    dvc.model = self.sourceArr[indexPath.row];
    dvc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:dvc animated:YES];
}

-(void)setUp{
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [UIView new];
    [self.tableView registerNib:[UINib nibWithNibName:@"GPIndexListCell" bundle:nil] forCellReuseIdentifier:@"GPIndexListCell"];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
